//创建xml对象函数
function createXmlHttpRrquest()	{
	var xmlHttp=null;
	try{
		xmlHttp=new XMLHttpRequest();
	}catch (e){
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
 }
	return xmlHttp;
}
//var cr_album = document.getElementById("cr_album"); 
//cr_album.onclick = createAlbum; 
function createAlbum() {
	var cr_album = document.getElementById("cr_album");
	document.getElementById("album").innerHTML = "<form id=albumForm action=\"#\" method=\"post\">"
											+"标题：<input type=\"text\" size=\"30\" name=\"title\" id=\"title\"/><br />"
											+"标签：<input type=\"text\" size=\"30\" name=\"tag\" id=\"tag\"/><br />"
											+"描述<textarea name=\"description\" id=\"description\"  ></textarea><br />"
											+"<input type=\"button\" id=\save_album\" value=\"保存\" onclick=\"saveAlbum()\"/>"
											+"<input type=\"button\" id=\"cancel_album\" value=\"取消\" onclick=\"cancelAlbum()\"/>"
											+"</form>";
}
var xmlHttp = createXmlHttpRrquest(); 
function saveAlbum() {
	//创建xml对象
	
	var albumForm = document.forms["albumForm"]; 
	var title = albumForm["title"].value; 
	var tag = albumForm["tag"].value;
	var description = albumForm["description"].value;
	var queryString = "title=" + title + "&tag" + tag + "&description=" + description;
	//var url = "http://localhost/system/index.php/photo/createAlbum";
	var url = "photo/createAlbum";
	xmlHttp.onreadystatechange = callbackAlbum; //回调函数
	xmlHttp.open("POST",url,true);
	//xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
	xmlHttp.send(queryString);
}
//回调函数callbackAlbum
function callbackAlbum() {
	if (xmlHttp.readyState == 4){ 
		if(xmlHttp.status == 200) {
			document.getElementById("al").innerHTML = xmlHttp.responseText;
		} else {
			document.getElementById("al").innerHTML = "<p>failed</p>";
		}
	} 

}
					
function cancelAlbum() {
				
}

//up_again.onclick = uploadAgain;	
function uploadAgain() {
								var up_again = document.getElementById("up_again");
								//创建元素节点para用于上传
								var para = document.createElement("input");
								para.setAttribute("type","file");
								para.setAttribute("id","para");
								para.setAttribute("name","image");
								up_again.appendChild(para);
								//创建一个元素节点upload 上传
								var upload = document.createElement("input");
								upload.setAttribute("type","button");
								upload.setAttribute("value","上传");
								upload.setAttribute("id","upload");
								upload.setAttribute("onclick","upload()")
								upload.setAttribute("onclick","upload()");
								up_again.appendChild(upload);
								//创建rsub节点 取消
								var rsub = document.createElement("input");
								rsub.setAttribute("type","button");
								rsub.setAttribute("id","cancel")
								rsub.setAttribute("value","取消");
								rsub.setAttribute("onclick","cancel()");
								up_again.appendChild(rsub);
								
								
							}
							//上传函数
							function upload() {
								
							}
							//取消函数
							function cancel() {
								var upload = document.getElementById('upload');
								var cancel = document.getElementById('cancel');
								var para = document.getElementById('para');
								var parent = para.parentNode;
								parent.removeChild(upload);
								parent.removeChild(para);
								parent.removeChild(cancel)
							}
																	